package com.dingding.special.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dingding.common.core.base.controller.BaseController;
import com.dingding.common.core.base.dto.FacadeResult;
import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.common.core.util.paravalidate.ValidateUtil;
import com.dingding.order.code.order.PublishCarType;
import com.dingding.order.dto.phonecall.ReqGetPhoneCall;
import com.dingding.order.dto.phonecall.ResGetPhoneCall;
import com.dingding.order.service.ICarOrderFacade;
import com.dingding.order.service.IUserOrderFacade;

import net.sf.json.JSONObject;

/**
 * 
* @ClassName: CarOrderController.java 
* @Package com.dingding.special.controller 
* @Description: 司机订单公用接口类
* @author hufan
* @date 2016年11月21日 下午7:02:10 
* @version V2.5.6
 */
@Controller
@RequestMapping("/authorapi/driver/order")
public class CarOrderController extends BaseController {

	Logger logger = Logger.getLogger(TaxiOrderController.class);

	@Resource(name = "carOrderFacade")
	private ICarOrderFacade  carOrderFacade;
	
	@Resource(name = "userOrderFacade")
	private IUserOrderFacade userOrderFacade;
	
	/**
	 * @Description:获取taxi司机历史订单
	 * @author hufan
	 * @since 2.5.6
	 */
	@RequestMapping(value = "/v1/historicalOrder", method = { RequestMethod.POST })
	public void completeAndCancelOrder(HttpServletRequest request, HttpServletResponse response){
		
		String clientData = super.getClientData(request, response);
		
		JSONObject jsonObject = JSONObject.fromObject(clientData);
		Integer  userRole = 2;//默认查询专车
		if(jsonObject != null) {
			userRole = jsonObject.getJSONObject("requestBody").getInt("userRole");
		}
		
		String responseData = carOrderFacade.getDriverHistoryOrdersByCarType(clientData, userRole==2?PublishCarType.SPECIAL:PublishCarType.TAXI);
		super.responseData(response, responseData);
	}
	

	/**
	 * @Description:出租车抢单（抢预约单）
	 * @author hufan
	 * @since 2.5.6
	 */
	@RequestMapping(value = "/v2/grabOrder", method = { RequestMethod.POST })
	public void grabOrder(HttpServletRequest request, HttpServletResponse response) {

		String clientData = super.getClientData(request, response);
		
		JSONObject jsonObject = JSONObject.fromObject(clientData);
		Integer  userRole = 2;//默认查询专车
		if(jsonObject != null) {
			userRole = jsonObject.getJSONObject("requestBody").getInt("userRole");
		}
		
		String responseData = carOrderFacade.driverGrabOrder(clientData, userRole==2?PublishCarType.SPECIAL:PublishCarType.TAXI);
		super.responseData(response, responseData);
	}
	
	
	/**
	 * @Description:获取拨打的电话号码
	 * @author hufan
	 * @since 2.5.6
	 */
	@RequestMapping(value = "/v1/getPhoneCall", method = RequestMethod.POST)
	public void getPhoneCall(HttpServletRequest request, HttpServletResponse response) {

		ReqGetPhoneCall reqGetPhoneCall = super.getRequestBean(request, response, ReqGetPhoneCall.class);

		// 验证参数是否为空
		if (ValidateUtil.validateBean(reqGetPhoneCall, ReqGetPhoneCall.class) == false) {
			super.generateNullParamRes(response);
		}

		FacadeResult<ResGetPhoneCall> phoneCall = this.userOrderFacade.getPhoneCall(reqGetPhoneCall);

		super.generateFacadeResponse(response, new ResponseEntity<ResGetPhoneCall>(), phoneCall);
	}
	
}
